const { initMainKnex, ensureGlobalTables, getMainKnex, getCaseDatabaseInfo } = require('./knex');

async function initDatabase(projectRoot) {
    // 1. Initialize Knex instance
    initMainKnex(projectRoot);

    // 2. Ensure global tables exist
    await ensureGlobalTables();

    console.log('Database initialized successfully');
}

function getDb() {
    return getMainKnex();
}

async function getCaseDatabase(caseId) {
    const { knex } = await getCaseDatabaseInfo(caseId);
    return knex;
}

module.exports = {
    initDatabase,
    getDb,
    getCaseDatabase
};
